<?php
// +----------------------------------------------------------------------
// |  [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 111 All rights reserved.
// +----------------------------------------------------------------------
// | Author:
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\common\controller\Admin;

/**
 * 用户充值
 * Class Recharge
 * @package app\admin\controller
 */
class Recharge extends Admin
{

    /**
     * 充值首页
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $param = $this->request->param();
        $map = [];

//		$map['status'] = array('egt', 0);
//		if (isset($param['nickname']) && $param['nickname']) {
//			$map['nickname'] = array('like', '%' . $param['nickname'] . '%');
//		}
//		if (isset($param['username']) && $param['username']) {
//			$map['username'] = array('like', '%' . (string) $param['nickname'] . '%');
//		}


        if (isset($param['uid']) && $param['uid'] > 0) {
            $map['uid'] = $param['uid'];
        }

        $list = model('userRecharge')->where($map)->order('id desc')
            ->paginate(15, false, array(
                'param' => $param
            ));

        $data = array(
            'list' => $list,
            'page' => $list->render(),
            'param' => $param
        );
        $this->assign($data);
        $this->setMeta('用户充值信息');
        return $this->fetch();
    }


    /**
     * 手动充值
     * @return mixed
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function add()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();

            $result = \app\common\serve\User::ManualRecharge($params);

            if (is_array($result) && $result['code'] == 1) {
                $this->success($result['msg'], 'index');
            } else {
                $this->error($result['msg']);
            }

        } else {

            $link = model('UserRecharge');

            $data = array(
                'keyList' => $link->keyList,
            );

            $this->assign($data);
            $this->setMeta('人工客服充值');
            return $this->fetch('public/edit');
        }
    }

}